package com.wangdong.ceshirenlianhangxin.fragment;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.wangdong.ceshirenlianhangxin.R;
import com.wangdong.ceshirenlianhangxin.SilentLivenessImageHolder;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class ResultFragment extends BaseFragment{

    private ImageView mResultImageView = null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_result_page, container, false);
        mResultImageView = (ImageView)view.findViewById(R.id.img_result);
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();

        Bitmap face = SilentLivenessImageHolder.getImageData();
        saveBitmapToFile(face, "/sdcard/sensetime/face.jpg");
        mResultImageView.setImageBitmap(SilentLivenessImageHolder.getImageData());
    }

    private void saveBitmapToFile(Bitmap var0, String var1) {
        try {
            File var3;
            if((var3 = new File(var1)).exists() || !var3.getParentFile().mkdirs() || var3.createNewFile()) {
                BufferedOutputStream var4 = new BufferedOutputStream(new FileOutputStream(var3));
                var0.compress(Bitmap.CompressFormat.JPEG, 80, var4);
                var4.close();
            }
        } catch (IOException var2) {
            var2.printStackTrace();
        }
    }
}